//
//  CCDHaveRecStaffCell.m
//  operativeSide
//
//  Created by 王春程 on 16/5/31.
//  Copyright © 2016年 com.caocaod.www. All rights reserved.
//

#import "CCDHaveRecStaffCell.h"
#import "Masonry.h"
#import "CBAutoScrollLabel.h"



@interface CCDHaveRecStaffCell()

@property (strong, nonatomic)               UILabel *nameLabel;  //名字
@property (strong, nonatomic)               UIImageView *nameImageView;
@property (strong, nonatomic)               UILabel *name;

@property (strong, nonatomic)               UILabel *addressLabel;  // 地址
@property (strong, nonatomic)               UIImageView *addressImageView;
@property (strong, nonatomic)               UILabel *address;

@property (strong, nonatomic)               UILabel *phoneLabel;  //手机号
@property (strong, nonatomic)               UIImageView *phoneImageView;
@property (strong, nonatomic)               UILabel *phone;

@property (strong, nonatomic)               UILabel *timeLabel; //时间
@property (strong, nonatomic)               UIImageView *timeImageView;
@property (strong, nonatomic)               UILabel *time;

@property (strong, nonatomic)               UILabel *lineLabel; // 头部线性
@property (strong, nonatomic)               UIView *backView;  // 底部背景白色View
@property (strong, nonatomic)               CBAutoScrollLabel *autoLabel;
@property (strong, nonatomic)               UILabel *codeLabel;

@property (strong, nonatomic)               UIImageView *recAddressImageView;
@property (strong, nonatomic)               UILabel *recAddressLabel;
@property (strong, nonatomic)               CBAutoScrollLabel *recAddress;

@end
@implementation CCDHaveRecStaffCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self autoLayOut];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)autoLayOut {
    WS(ws);
    _lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, 10)];
    _lineLabel.backgroundColor = RGB(232, 232, 232);
    [self.contentView addSubview:self.lineLabel];
    
    _backView = [[UIView alloc] init];
    _backView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.backView];
    [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView.mas_left);
        make.top.mas_equalTo(ws.lineLabel.mas_bottom);
        make.right.mas_equalTo(ws.contentView.mas_right);
        make.bottom.mas_equalTo(ws.contentView.mas_bottom);
    }];
    
    _nameImageView = [[UIImageView alloc] init];
    _nameImageView.image = [UIImage imageNamed:@"name"];
    [self.backView addSubview:self.nameImageView];
    [_nameImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView.mas_left).offset(18);
        make.top.mas_equalTo(ws.backView.mas_top).offset(6);
        make.size.mas_equalTo(CGSizeMake(12, 17));
    }];
    
    
    _nameLabel = [[UILabel alloc] init];
    _nameLabel.text = @"姓名 :";
    CGSize size = [self.nameLabel sizeThatFits:CGSizeMake(CGFLOAT_MAX, 14)];
    _nameLabel.font = [UIFont systemFontOfSize:14];
    _nameLabel.textColor = RGB(51, 51, 51);
    [self.backView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView.mas_left).offset(51);
        make.centerY.mas_equalTo(ws.nameImageView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(size.width, 16));
    }];
    
    _name = [[UILabel alloc] init];
    _name.textColor = RGB(51, 51, 51);
    _name.font = [UIFont systemFontOfSize:14];
    [self.backView addSubview:self.name];
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.nameLabel.mas_right).offset(10);
        make.centerY.mas_equalTo(ws.nameImageView.mas_centerY);
        make.right.mas_equalTo(ws.backView.mas_right).offset(-15);
        make.height.mas_equalTo(16);
    }];
    
    _phoneImageView = [[UIImageView alloc] init];
    _phoneImageView.image = [UIImage imageNamed:@"workphone"];
    [self.backView addSubview:self.phoneImageView];
    [self.phoneImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView.mas_left).offset(15);
        make.top.mas_equalTo(ws.nameImageView.mas_bottom).offset(11);
        make.size.mas_equalTo(CGSizeMake(17, 17));
    }];
    
    
    _phoneLabel = [[UILabel alloc] init];
    _phoneLabel.text = @"手机 :";
    _phoneLabel.textColor = RGB(51, 51, 51);
    _phoneLabel.font = [UIFont systemFontOfSize:14];
    [self.backView addSubview:self.phoneLabel];
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView.mas_left).offset(51);
        make.centerY.mas_equalTo(ws.phoneImageView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(size.width, 16));
    }];
    
    _phone = [[UILabel alloc] init];
    _phone.textColor = RGB(51, 51, 51);
    _phone.font = [UIFont systemFontOfSize:14];
    [self.backView addSubview:self.phone];
    [self.phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.phoneLabel.mas_right).offset(10);
        make.centerY.mas_equalTo(ws.phoneImageView.mas_centerY);
        make.right.mas_equalTo(ws.backView.mas_right).offset(-15);
        make.height.mas_equalTo(16);
    }];
    
    _addressImageView = [[UIImageView alloc] init];
    _addressImageView.image = [UIImage imageNamed:@"address"];
    [self.backView addSubview:self.addressImageView];
    [_addressImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView.mas_left).offset(18);
        make.top.mas_equalTo(ws.phoneImageView.mas_bottom).offset(12);
        make.size.mas_equalTo(CGSizeMake(13, 17));
    }];
    
    _addressLabel = [[UILabel alloc] init];
    _addressLabel.text = @"地址 :";
    _addressLabel.textColor = RGB(51, 51, 51);
    _addressLabel.font = [UIFont systemFontOfSize:14];
    [self.backView addSubview:self.addressLabel];
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView.mas_left).offset(51);
        make.centerY.mas_equalTo(ws.addressImageView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(size.width, 16));
    }];
    
    _autoLabel = [[CBAutoScrollLabel alloc] init];
    _autoLabel.textColor = RGB(51, 51, 51);
    _autoLabel.labelSpacing = 40; // distance between start and end labels
    _autoLabel.pauseInterval = 1.7;// seconds of pause before scrolling starts again
    _autoLabel.scrollSpeed = 30; // pixels per second
    _autoLabel.textAlignment = NSTextAlignmentLeft; // centers text when no auto-scrolling is applied
    _autoLabel.fadeLength = 12.f;
    _autoLabel.font = [UIFont systemFontOfSize:14];
    _autoLabel.scrollDirection = CBAutoScrollDirectionLeft;
    [_autoLabel observeApplicationNotifications];
    [self.contentView addSubview:self.autoLabel];
    [_autoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.addressLabel.mas_right).offset(10);
        make.centerY.mas_equalTo(ws.addressImageView.mas_centerY);
        make.right.mas_equalTo(ws.backView.mas_right).offset(-15);
        make.height.mas_equalTo(16);
    }];
    
    _timeImageView = [[UIImageView alloc] init];
    _timeImageView.image = [UIImage imageNamed:@"time"];
    [self.backView addSubview:self.timeImageView];
    [_timeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView.mas_left).offset(18);
        make.top.mas_equalTo(ws.addressImageView.mas_bottom).offset(11);
        make.size.mas_equalTo(CGSizeMake(13, 16));
    }];
    
    _timeLabel = [[UILabel alloc] init];
    _timeLabel.text = @"时间 :";
    _timeLabel.textColor = RGB(51, 51, 51);
    _timeLabel.font = [UIFont systemFontOfSize:14];
    [self.backView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView.mas_left).offset(51);
        make.centerY.mas_equalTo(ws.timeImageView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(size.width, 16));
    }];
    
    _time = [[UILabel alloc] init];
    _time.textColor = RGB(51, 51, 51);
    _time.font = [UIFont systemFontOfSize:14];
    [self.backView addSubview:self.time];
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.timeLabel.mas_right).offset(10);
        make.centerY.mas_equalTo(ws.timeImageView.mas_centerY);
        make.right.mas_equalTo(ws.backView.mas_right).offset(-15);
        make.height.mas_equalTo(16);
    }];
    
    _name.text = @"马云";
    _phone.text = @"13888888888";
    _autoLabel.text = @"asdkasjkldjaksljklasjkldasjkldjlkasdljkasjkldajlskdkjlasjkld";
    _time.text = @"2016-12-16";
     
}

- (void)setPiece:(staffModelJPieces *)piece {
    _piece = piece;
    self.time.text = piece.timeAdd;

    if(piece.areaCode.length != 0) {
        self.codeLabel.text = [NSString stringWithFormat:@"区编 ：%@",piece.areaCode];
    } else {
        self.codeLabel.text = @"区编 ：未划";
    }
    self.name.text = piece.nameSender;
    self.phone.text = piece.phoneSender;
    self.time.text = piece.timeAdd;
    self.autoLabel.text = piece.addressSender;
    [self.autoLabel refreshLabels];
    self.recAddress.text = piece.addressRecipient;
    [self.recAddress refreshLabels];
    
}
@end


